<template>
  <div class="login">
    <div class="con">
      <h2 class="text-center h2">登录</h2>
      <el-input placeholder="请输入用户名" v-model="user.username" clearable focus> </el-input>
      <el-input placeholder="请输入密码" v-model="user.password" show-password clearable></el-input>
      <div class="text-center">
         <el-button type="primary" round @click="login">登录</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {requserlogin} from '../../http/api'
import { mapGetters, mapActions } from "vuex";
export default {
  data(){
    return{
      user:{
        username:'',
        password:'',
      }
    }
  },
  methods:{
    ...mapActions({changeUserInfo:"changeUserInfo"}),
    async login(){
      let {data:res} = await requserlogin(this.user);
      if(res.code == 200){
        this.changeUserInfo(res.list);
        this.$router.push('/');
      }
    }
  }
};
</script>

<style scoped lang="less">
@import "../../less/index.less";
.login {
  position: relative;
  width: 100vw;
  height: 100vh;
  background: linear-gradient(to right, @primary-light, @primary-deep);
  .con {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 380px;
    padding: @margin20;
    border-radius: @padding10;
    background-color: #fff;
    transform: translate(-50%, -50%);
    h2{
      margin-bottom:  @margin20;
    }
    .el-input{
      margin-bottom: @margin20;
    }
  }
}
</style>